package com.greensam.pixelengine.websocket.dto;

import com.greensam.pixelengine.websocket.constant.MessageCode;
import com.greensam.pixelengine.websocket.constant.WebSocketEventType;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author Ma Chengrui
 * @since 2025/10/10 16:37
 */
@Data
@NoArgsConstructor
public class WebSocketPushMessage<T> {

    /**
     * 消息事件类型
     */
    private WebSocketEventType type;

    /**
     * 消息code
     */
    private MessageCode code;

    /**
     * 具体数据
     */
    private T data;

    /**
     * 服务器时间戳
     */
    private String timestamp;

    public WebSocketPushMessage(WebSocketEventType type, MessageCode code, T data) {
        this.type = type;
        this.data = data;
        this.code = code;
        this.timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
    }

}
